package org.example.basic.lambda.stream;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 〈〉<br>
 *
 * @author Mr.Wang
 * @create 2022/1/14
 */
public class StreamSorted {

    /**
     * @Author Mr.Wang
     * @Description 排序用法
     * @Date 3:43 PM 2022/1/14
     *
     * Comparator.nullsFirst	排序字段为null的对象放在排序后的List最后面
     * Comparator.nullsLast	    排序字段为null的对象放在排序后的List最前面
     *
     **/
    public static void main(String[] args) {
        List<Integer> sysMenuList=new ArrayList<>();
        sysMenuList.add(5);
        sysMenuList.add(3);
        sysMenuList.add(1);
        List<Integer> integers = new ArrayList<>();
        sysMenuList.forEach(System.out::println);
        integers= sysMenuList.stream().sorted(Comparator.comparing(Integer::intValue)).collect(Collectors.toList());
        List<Integer> ss=sysMenuList.stream().sorted(
                        Comparator.comparing(Integer::intValue,Comparator.nullsFirst(Integer::compareTo)).reversed())
                .collect(Collectors.toList());
        integers.stream()
                .forEach(s-> System.out.println("integers = " + s));
        ss.forEach(System.out::println);
    }
}